﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuickLifeHall.ERP.Utilities
{
    public class PageBase : System.Web.UI.Page
    {
        public PageBase()
            : base()
        {
            
        }

        /// <summary>
        /// 是否登陆
        /// </summary>
        protected bool IsLogin = false;

        /// <summary>
        /// 当前登陆用户
        /// </summary>
        protected Entity.SystemBase.User LoginUser = null;

        /// <summary>
        /// 页面访问类型，默认需要登陆，并过滤权限
        /// </summary>
        protected Core.Web.PageAccessType PageAccessType = Core.Web.PageAccessType.Authorization;

        /// <summary>
        /// 当前页面要执行的操作
        /// </summary>
        protected string Action = string.Empty;

        protected override void OnInit(EventArgs e)
        {
            this.IsLogin = Facade.Utilities.PermissionUtility.IsLogin(this.Context, out LoginUser);

            if (PageAccessType == Core.Web.PageAccessType.Authorization)
            {
                if (!IsLogin || this.LoginUser == null)
                {
                    this.Response.Redirect("/Login.aspx", true);
                }
            }

            this.Action = Request["Action"];

            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            _ExecuteAction();

            base.OnLoad(e);
        }

        protected virtual void _ExecuteAction()
        {

        }
    }
}